/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = jboss_sub_parse.c                          */
/*  NOTE      =                                                    */
/*  DATE      = 2015/11/19 by geyh                                 */
/*******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include <jbossmq/jbossmq_comm.h>
#include <jbossmq/jbossmq_core.h>
#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "frbyte_buffer.h"
#include "frlist.h"
#include "frreport_comm.h"
#include "apmtest_cunit.h"
#include "apmtest_comm.h"

#include "../../../src/module/jbossmq/config.h"


static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

int jboss_sub_parse(Frbyte_Packet *p_st_data, Frreport_body_data *p_st_body_data , L7session_jboss_private *p_st_private, int i_flag_need);
extern L7session_jboss_private* __jboss_private_create(void);

static void __case1(void)
{
    int i_ret = 0;
    L7session_jboss_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;

    i_ret = apmtest_create_ct(&p_st_conn, jboss_session_destroy, (char *)"192.168.0.1", (char *)"192.168.0.35", 5460, 5672);
    p_st_body_data = frreport_body_new_l7 (p_st_conn);

    p_st_private = __jboss_private_create();

    bytebuff_add(p_st_private->p_st_data , (char *)"\x00\x00\x00\x00\x00\x00\x00\x0b\x00\x00\x00\x26\x6a\x00\x6d\x00\x73"
            "\x00\x2e\x00\x71\x00\x75\x00\x65\x00\x75\x00\x65\x00\x2e\x00\x74\x00\x65\x00\x73\x00\x74\x00\x51\x00\x75\x00"
            "\x65\x00\x75\x00\x65\x00", 94);

    i_ret = jboss_sub_parse(p_st_private->p_st_data, p_st_body_data, p_st_private, 1);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    jboss_session_destroy(p_st_private);
    frreport_body_free(&p_st_body_data);
    apmtest_destroy_ct(&p_st_conn);

    return;

}


static void __case2(void)
{
    int i_ret = 0;
    L7session_jboss_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;

    i_ret = apmtest_create_ct(&p_st_conn, jboss_session_destroy, (char *)"192.168.0.1", (char *)"192.168.0.35", 5460, 5672);
    p_st_body_data = frreport_body_new_l7 (p_st_conn);

    p_st_private = __jboss_private_create();

    i_ret = jboss_sub_parse(p_st_private->p_st_data, p_st_body_data, p_st_private, 0);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    jboss_session_destroy(p_st_private);
    frreport_body_free(&p_st_body_data);
    apmtest_destroy_ct(&p_st_conn);

    return;

}


static void __case3(void)
{
    int i_ret = 0;
    L7session_jboss_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;

    i_ret = apmtest_create_ct(&p_st_conn, jboss_session_destroy, (char *)"192.168.0.1", (char *)"192.168.0.35", 5460, 5672);
    p_st_body_data = frreport_body_new_l7 (p_st_conn);

    p_st_private = __jboss_private_create();

    bytebuff_add(p_st_private->p_st_data , (char *)"\x00\x00\x00\x00\x00\x00\x00\x0b\x00\x00\x00\x26\x6a\x00\x6d\x00\x73"
            "\x00\x2e\x00\x71\x00\x75\x00\x65\x00\x75\x00\x65\x00\x2e\x00\x74\x00\x65\x00\x73\x00\x74\x00\x51\x00\x75\x00"
            "\x65\x00\x75\x00\x65\x00", 94);

    i_ret = jboss_sub_parse(p_st_private->p_st_data, p_st_body_data, p_st_private, 0);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    jboss_session_destroy(p_st_private);
    frreport_body_free(&p_st_body_data);
    apmtest_destroy_ct(&p_st_conn);

    return;

}


int add_suite_jboss_sub_parse(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" jboss_sub_parse()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);


    return FR_SUCC;

}
